vacuum2 2.2.1
Loading...
Searching...
No Matches
vacuum2.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2026 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef VACUUM2_H
29#define VACUUM2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_analog_in.h"
52#include "drv_i2c_master.h"
53
59
64
69
74#define VACUUM2_PRESSURE_PA_MIN -2000
75#define VACUUM2_PRESSURE_PA_MAX 2000
76#define VACUUM2_PRESSURE_SENS_PA 0.001
77#define VACUUM2_ADC_VOUT_MULTIPLIER 2
78
83#define VACUUM2_NUM_CONVERSIONS 200
84
89#define VACUUM2_ADC_RESOLUTION 0x0FFF
90#define VACUUM2_VREF_3V3 3.3
91#define VACUUM2_VREF_5V 5.0
92
97#define VACUUM2_TIMEOUT_MS 2000
98
104#define VACUUM2_SET_DEV_ADDR 0x4D
105 // vacuum2_set
107
112
117
122#define VACUUM2_MAP_MIKROBUS( cfg, mikrobus ) \
123 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
124 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
125 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
126 // vacuum2_map // vacuum2
129
140
145typedef struct
146{
147 analog_in_t adc;
148 i2c_master_t i2c;
149
151 float vref;
154
155} vacuum2_t;
156
161typedef struct
162{
163 pin_name_t an;
164 pin_name_t scl;
165 pin_name_t sda;
166
167 analog_in_resolution_t resolution;
168 float vref;
169
170 uint32_t i2c_speed;
171 uint8_t i2c_address;
172
174
176
181typedef enum
182{
185
187
193
204
220
235
247err_t vacuum2_read_adc_raw ( vacuum2_t *ctx, uint16_t *raw_adc );
248
260err_t vacuum2_read_adc_voltage ( vacuum2_t *ctx, float *voltage );
261
273err_t vacuum2_set_vref ( vacuum2_t *ctx, float vref );
274
286err_t vacuum2_read_vout ( vacuum2_t *ctx, float *vout );
287
300err_t vacuum2_read_vout_avg ( vacuum2_t *ctx, uint16_t num_conv, float *vout_avg );
301
313
325err_t vacuum2_read_pressure ( vacuum2_t *ctx, int16_t *pressure );
326
327#ifdef __cplusplus
328}
329#endif
330#endif // VACUUM2_H
331 // vacuum2
333
334// ------------------------------------------------------------------------ END
void vacuum2_drv_interface_sel(vacuum2_cfg_t *cfg, vacuum2_drv_t drv_sel)
Vacuum 2 driver interface setup function.
err_t vacuum2_read_adc_raw(vacuum2_t *ctx, uint16_t *raw_adc)
Vacuum 2 read raw ADC value function.
err_t vacuum2_calib_offset(vacuum2_t *ctx)
Vacuum 2 calib offset function.
err_t vacuum2_set_vref(vacuum2_t *ctx, float vref)
Vacuum 2 set vref function.
err_t vacuum2_read_adc_voltage(vacuum2_t *ctx, float *voltage)
Vacuum 2 read voltage level function.
err_t vacuum2_read_pressure(vacuum2_t *ctx, int16_t *pressure)
Vacuum 2 read pressure function.
void vacuum2_cfg_setup(vacuum2_cfg_t *cfg)
Vacuum 2 configuration object setup function.
err_t vacuum2_read_vout(vacuum2_t *ctx, float *vout)
Vacuum 2 read vout function.
err_t vacuum2_read_vout_avg(vacuum2_t *ctx, uint16_t num_conv, float *vout_avg)
Vacuum 2 read vout avg function.
err_t vacuum2_init(vacuum2_t *ctx, vacuum2_cfg_t *cfg)
Vacuum 2 initialization function.
Vacuum 2 Click configuration object.
Definition vacuum2.h:162
analog_in_resolution_t resolution
Definition vacuum2.h:167
float vref
Definition vacuum2.h:168
vacuum2_drv_t drv_sel
Definition vacuum2.h:173
uint32_t i2c_speed
Definition vacuum2.h:170
pin_name_t scl
Definition vacuum2.h:164
pin_name_t sda
Definition vacuum2.h:165
pin_name_t an
Definition vacuum2.h:163
uint8_t i2c_address
Definition vacuum2.h:171
Vacuum 2 Click context object.
Definition vacuum2.h:146
float zero_press_offset
Definition vacuum2.h:152
float vref
Definition vacuum2.h:151
vacuum2_drv_t drv_sel
Definition vacuum2.h:153
i2c_master_t i2c
Definition vacuum2.h:148
uint8_t slave_address
Definition vacuum2.h:150
analog_in_t adc
Definition vacuum2.h:147
vacuum2_return_value_t
Vacuum 2 Click return value data.
Definition vacuum2.h:182
@ VACUUM2_ERROR
Definition vacuum2.h:184
@ VACUUM2_OK
Definition vacuum2.h:183
vacuum2_drv_t
Vacuum 2 Click driver selector.
Definition vacuum2.h:135
@ VACUUM2_DRV_SEL_ADC
Definition vacuum2.h:136
@ VACUUM2_DRV_SEL_I2C
Definition vacuum2.h:137